$(document).ready(function(){
//登陆后过期清除登陆信息
        if(localStorage.getItem("u_name")!=null&&localStorage.getItem("u_psd")!=null){
            var exp = 1000 * 60 * 60 ;//过期时间为1小时1000 * 60 * 60
            //获取本地值
            let item_name = localStorage.getItem("u_name");
            let item_pwd = localStorage.getItem("u_psd");
            //把本地值转换成json数据
            // let name = JSON.parse(item_name);
            // let pwd = JSON.parse(item_pwd);
            // (当前时间 - 存储的元素在创建时候设置的时间) > 过期时间
            var time= localStorage.getItem("curtime");
            var isTimed=(new Date().getTime()-time) >exp;
            console.info("我是=======过期时间:=="+exp);


            if(isTimed){
                //过期了
                localStorage.removeItem("u_name");
                localStorage.removeItem("u_psd");
                $("#errorlog").text("您的免密登陆已过期!");
            }else{
                //没过期
                //把存储的登陆信息显示在input里
                $("#u_name").val(item_name);
                $("#u_psd").val(item_pwd);
            }
        }

        $("#nologin").click(function () {
            //选择了免登陆----登陆信息存在本地,并设置时间
             localStorage.setItem("u_name",$("#u_name").val());
             localStorage.setItem("u_psd",$("#u_psd").val());
            var curtime = new Date().getTime(); //获取当前时间
            localStorage.setItem("curtime",curtime);
        });
        //点击登录，判断账号密码对应跳转到首页
        $("#loginbtn").click(function () {
            $.ajax({
                type:"post",
                url:"user/login",
                async:true,
                dataType:"json",
                data:{
                    u_name:$("#u_name").val(),
                    u_psd:$("#u_psd").val()

                },
                success:function(rs){
                    var errorCode = rs.errorCode;

                    if (errorCode==0){
                        $(location).attr("href","gotoindex");
                    } else{
                        var msg = rs.status;
                        $("#errorlog").text(msg);
                        $("#errorlog").removeClass("hidden");

                    }


                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    this;
                }
            });
        });

    $(".img-circle").click(function () {
        $(location).attr("href","gotoregister");
    });
});
